#pragma once
#include "p2.h"
#include "AccountInfo.h"
#include "PositionInfo.h"
#include "KRSTHeader.h"

class CMainOrderPanel;
class CAccountInfo;
class CAccountManager
{
public:
	CAccountManager(IGxServer& a_Server);
	
	CAccountManager();
	~CAccountManager();

	
	IGxServer m_Server;
	void OnAccountUndated();
	CAccountInfo* RefreshAccount();

	CMainOrderPanel* MainWnd() const { return m_pMainWnd; }
	void MainWnd(CMainOrderPanel* val) { m_pMainWnd = val; }

	CString m_AccountCode;

	void ChangeAccount(CString a_AccountCode);
	void AddAccounts(IGxServer& a_Server);

	// KR
	void ReadAccountInfo(HMODULE a_hModule);

	void RequestOrderAvailable(HMODULE a_hModule, string a_AccCode, string a_SymCode, int a_Mmgb, double a_Price);
	void OnOrderAvailable(lpExpTr5130O_st a_Info);

	void RequestJangoState(HMODULE a_hModule, string a_NextKey, CAccountInfo* a_Acc);
	void RequestFillState(HMODULE a_hModule, string a_NextKey, CAccountInfo* a_Acc);
	void RequestFillState(HMODULE a_hModule, string a_Range, string a_By, string a_NextKey, CAccountInfo* a_Acc);
	bool m_ReceivedOrderState;
	bool m_ReceivedFillState;

	void OnJangoChanged(char* a_Jango, CAccountInfo* a_CurAcc);
	void OnPositionUpdated(HMODULE a_hModule, string a_AccCode, lpExpTr5112Sub a_SubInfo);
	void OnPositionUpdated(string a_AccCode, lpExpTr0988O_sub a_Order);
	void UpdateUnfilledOrderCount(CAccountInfo* a_CurAccount, string a_Symcode);

	void RequestTotalJango(HMODULE a_hModule, string a_NextKey, CAccountInfo* a_Acc);
	void RequestTradeState(HMODULE a_hModule, string a_NextKey, CAccountInfo* a_Acc);

	mapPosition m_PositionMap;

	CPositionInfo* AddPosition(string a_Key);
	CPositionInfo* FindPosition(string a_Key);

	bool m_RequestOrderAvailableComplete;

private:

	CMainOrderPanel* m_pMainWnd;
};

